﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace SGCG.Model
{
    public abstract class GroupBase: GraphicObject, IEnumerable<GraphicObject>
    {
        protected IEnumerable<GraphicObject> rawGraphicObjects;

        protected GroupBase(GraphicObject parent) : base(parent) { }

        public GroupBase(GraphicObject parent, IEnumerable<GraphicObject> graphicObjects)
            : base(parent)
        {
            this.rawGraphicObjects = graphicObjects;
            this.rawGraphicObjects.Each(g => g.Parent = this);
        }

        public override GraphicObject Attach(IDrawingCanvas drawingCanvas)
        {
            base.Attach(drawingCanvas);
            this.Each(graphicObject => graphicObject.Attach(drawingCanvas));
            return this;
        }

        public override void Draw()
        {
            rawGraphicObjects.Each(graphicObject => graphicObject.Draw());
        }

        public override bool Selected
        {
            get
            {
                return base.Selected;
            }

            set
            {
                this.Each(graphicObjects => graphicObjects.Selected = value);
                base.Selected = value;
            }
        }

        public IEnumerator<GraphicObject> GetEnumerator()
        {
            return this.rawGraphicObjects.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return ((System.Collections.IEnumerable)this.rawGraphicObjects).GetEnumerator();
        }

        public override void ConsolidateTransform(ITransform transform)
        {
            rawGraphicObjects.Each(graphicObject => graphicObject.ConsolidateTransform(transform));
        }
    }
}
